package com.github.base.controller;

import com.github.base.annotation.SysLog;
import com.github.base.dto.permission.PermissionDTO;
import com.github.base.dto.permission.PermissionMoveDTO;
import com.github.base.service.PermissionService;
import com.github.base.utils.Result;
import com.github.base.validated.Update;
import com.github.base.vo.permission.PermissionVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: base
 * @description: 权限
 * @author: hui.zhang
 * @date: 2021/1/27 5:04 下午
 **/

@RestController
@Tag(name = "权限资源")
@RequestMapping("/permission")
@ApiSupport(author = "zhanghui")
@RequiredArgsConstructor
public class PermissionController {
    private final PermissionService permissionService;


    @PostMapping("/save")
    @Operation(summary = "新增权限资源")
    @ApiOperationSupport(order = 1)
    @SysLog(module = "权限资源模块", value = "新增权限资源")
    public Result<?> save(@Validated @RequestBody PermissionDTO dto) {
        permissionService.save(dto);
        return Result.ok();
    }

    @PostMapping("/delete/{id}")
    @Operation(summary = "删除权限资源")
    @ApiOperationSupport(order = 2)
    @SysLog(module = "权限资源模块", value = "删除权限资源")
    public Result<?> delete(@PathVariable("id") Long id) {
        return permissionService.deleteById(id);
    }


    @PostMapping("/update")
    @Operation(summary = "修改权限资源")
    @ApiOperationSupport(order = 3)
    @SysLog(module = "权限资源模块", value = "修改权限资源")
    public Result<?> update(@Validated(Update.class) @RequestBody PermissionDTO dto) {
        permissionService.update(dto);
        return Result.ok();
    }


//    @GetMapping("/getTree")
//    @Operation(summary = "资源树")
//    @ApiOperationSupport(order = 4)
//    public Result<List<Tree<Long>>> getTree() {
//        return permissionService.getTree();
//    }


    @PostMapping("/move")
    @Operation(summary = "权限移动拖拽")
    @ApiOperationSupport(order = 5)
    public Result<?> move(@RequestBody PermissionMoveDTO dto) {
        permissionService.move(dto);
        return Result.ok();
    }

    @GetMapping("/current")
    @Operation(summary = "获取当前人的权限列表")
    @ApiOperationSupport(order = 6)
    public Result<List<PermissionVO>> currentInfo() {
        return Result.ok(permissionService.currentInfo());
    }


}
